<style>
.btn.btn-success-o{
    background: #fff;
    border: 1px solid red;
    color: #333;
}
.btn.btn-success-o.active{
    background: #fdb2b2;
    border: 1px solid red;
    color: red;
}
.btn.btn-success-o.active .subtitle{
    color: red;
}
.btn.btn-success-o.active::after{content:" ";width:23px;height:24px;background:url(../core/resource/images/gou-red.png) no-repeat;position:absolute;float:right;right:-1px;bottom:-1px;text-align:center;}
.jy-image-typetitle {
    float: right;
    top: 0.3rem;
    left: 0.2rem;
    padding: 2px 6px;
    position: absolute;
    color: #fff;
    background: #f60;
    font-size: 12px;
    border-bottom-right-radius: 16px;
	border-top-left-radius: 16px;
    z-index: 3;
}
.fui-cell-group .deleteitem {position: absolute;color:red;margin-top:-0.3rem;right:0.5rem}
</style>
<div class='fui-page fui-page-current'>
    <div class="fui-content">
		<div style="padding:0 0.5rem">
		<div style="padding:0.2rem;padding-top:1rem">
		<div class='bold' style="font-size:1rem">{{pagedata.typetitle}}</div>
		<div class='gray' style="font-size:0.6rem">当前仓库员：{{pagedata.worker.title}}</div>
		</div>
		<div class="fui-cell-group radius" style="margin-top:0.5rem">
			<div class="fui-cell">
				<div class="fui-cell-text bold">
					箱标
				</div>
				<div class="fui-cell-remark noremark red" ng-click="pagedata.scanxcode()" style="font-size:0.6rem">
					扫码1个箱标 <i class="icon icon-saoyisao2" style="font-size:0.6rem"></i>
				</div>
            </div>
			<div class="fui-cell" style="padding-top:0">
				<div class="fui-cell-text">
					<input type="text" class="fui-input" id="code" placeholder="扫码录箱标" ng-model="pagedata.nowxcode" ng-blur="pagedata.addxcode()"/>
					<div class="help red" style="font-size:0.6rem">提示：点击输入框出现光标，用扫码抢扫码/手机直接扫码即可！</div>
				 </div>
            </div>
		</div>
		<div class="fui-cell-group radius" style="margin-top:0.5rem">
			<div class="fui-cell">
				<div class="fui-cell-text bold">
					盒标签
				</div>
				<div class="fui-cell-remark noremark red" ng-click="pagedata.scancode()" style="font-size:0.6rem">
					扫码48个盒标 <i class="icon icon-saoyisao2" style="font-size:0.6rem"></i>
				</div>
            </div>
			<div class="fui-cell" style="padding-top:0">
				<div class="fui-cell-text">
					<input type="text" class="fui-input" id="code" placeholder="扫码录标签" ng-model="pagedata.nowcode"/>
					<div class="help red" style="font-size:0.6rem">提示：点击输入框出现光标，用扫码抢扫码/手机直接扫码即可！</div>
				</div>
            </div>
			<div class="fui-cell">
				<div class="fui-cell-text">盒标签列表</div>
				<div class="fui-cell-remark noremark">
				{{pagedata.item.codes.length||0}}个
				</div>
            </div>
			<div ng-repeat="item in pagedata.item.codes" class="fui-cell">
				<div class="fui-cell-label" style="width:1.5rem">
					{{$index+1}}
				</div>
				<div class="fui-cell-text" style="font-size:0.65rem">
					{{item.code}}
				</div>
				<div class="deleteitem" ng-click="pagedata.item.codes.splice($index,1)"><i class="icon icon-cuowu bold"></i></div>
            </div>
		</div>
		<a href="javascript:;" class='btn btn-success block' style="background:#7783EA;border-radius:1rem;line-height: 3;margin-top:1.5rem" ng-click="pagedata.subpost()">确认提交</a>
		<a href="javascript:;" class='btn btn-gray block' style="border-radius:1rem;line-height: 3;" ng-click="access_json('jy_goodserpfw/store.index/')"><<返回</a>
		<div ng-include="sys_html('common/_copyright',true)"></div>
		</div>
</div>
<script>
scope.pagedata.subpost=function(){
	if(scope.pagedata.issubpost){
		scope.message('请勿重复点击！','error')
		return '';
	}
	scope.pagedata.issubpost=1;
	scope.post_json('/store.uphelog/post/xcode='+scope.pagedata.nowxcode,scope.pagedata.item,function(res){
		scope.message(res);
	});
}
scope.pagedata.addcode=function(){
	if(!scope.pagedata.nowcode){
		return '';
	}
	if(!scope.pagedata.nowxcode){
		scope.message('请先扫码录箱标！','error')
		return '';
	}
	scope.pagedata.issubpost='';
	var nowcode=scope.pagedata.nowcode;
	if(nowcode.indexOf('code=')>=0){
		nowcode=nowcode.split('code=');
		if(!nowcode[1]){
			scope.message('二维码不正确！','error')
			scope.pagedata.nowcode=''
			scope.$evalAsync();
			return '';
		}
		scope.pagedata.nowcode=nowcode[1];
	}
	if(scope.pagedata.item.codes.length==48){
		scope.message('已经录入48个盒码了，不能再录入了！','error')
		return '';
	}
	scope.post_json('/store.uphelog/check_status/iszhuang=1&nowcode='+scope.pagedata.nowcode+'&nowxcode='+scope.pagedata.nowxcode,scope.pagedata.item,function(res){
		if(res.success!=1){
			console.log(res)
			scope.message(res.msg,'error')
			scope.pagedata.nowcode=''
			scope.$evalAsync();
			scope.pagedata.scancheck();
			return '';
		}
		for(var i=0;i<scope.pagedata.item.codes.length;i++){
			if(scope.pagedata.item.codes[i].code==scope.pagedata.nowcode){
				scope.pagedata.scancheck();
				return '';
			}
		}
		scope.pagedata.item.codes.push({
			'code':scope.pagedata.nowcode,
		});
		setTimeout(function(){
			scope.pagedata.nowcode=''
			scope.$evalAsync();
			scope.pagedata.scancheck();
		},100);
	});
}
scope.pagedata.scancheck=function (){
	setTimeout(function(){
				scope.confirm({
					'message':'扫下一个码？',
					'success':function(){
						scope.pagedata.scancode();
					},
					'fail':function(){}
				});
	},100);
}
scope.pagedata.scancode=function (){
	console.log('scanQRCodeOK');
	scope.pagedata.issubpost='';
	wx.scanQRCode({
		needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
		success: function (res) {
			var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
			if(result.indexOf('code=')>=0){
				result=result.split('code=');
				result=result[1];
			}
			if(!result){
				scope.message('二维码不正确！','error')
				return '';
			}
			scope.pagedata.nowcode=result;
			scope.pagedata.addcode();
		}
	});
}
scope.pagedata.addxcode=function(){
	if(!scope.pagedata.nowxcode){
		return '';
	}
	var nowxcode=scope.pagedata.nowxcode;
	scope.pagedata.issubpost='';
	if(nowxcode.indexOf('code=')>=0){
		nowxcode=nowxcode.split('code=');
		scope.pagedata.nowxcode=nowxcode[1];
		scope.post_json('/store.uphelog/check_xcode/nowxcode='+scope.pagedata.nowxcode,scope.pagedata.item,function(res){
			if(res.success!=1){
				console.log(res)
				scope.message(res.msg,'error')
				scope.pagedata.nowxcode='';
				scope.$evalAsync();
			}
		});
		scope.$evalAsync();
	}
}
scope.pagedata.scanxcode=function (){
	console.log('scanQRCodeOK');
	scope.pagedata.issubpost='';
	wx.scanQRCode({
		needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
		success: function (res) {
			var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
			if(result.indexOf('code=')>=0){
				result=result.split('code=');
				result=result[1];
			}
			scope.pagedata.nowxcode=result;
			scope.$evalAsync();
		}
	});
}
</script>